﻿package view.mainUI
{
    import com.sh.game.global.*;
    import flash.events.*;
    import morn.core.components.*;
    import morn.core.handlers.*;

    public class FaceGame extends FaceUI
    {
        private var ta:Object;
        private var ctrlDown:Boolean = false;

        public function FaceGame(param1)
        {
            var _loc_2:* = ConfigDictionary.data.face;
            list_face.array = _loc_2;
            list_face.renderHandler = new Handler(this.faceRender);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.doStop);
            this.addEventListener(MouseEvent.CLICK, this.doStop);
            GlobalLayer.instance.root.addEventListener(KeyboardEvent.KEY_DOWN, this.keyDown);
            GlobalLayer.instance.root.addEventListener(KeyboardEvent.KEY_UP, this.keyUp);
            this.ta = param1;
            return;
        }// end function

        protected function keyUp(event:KeyboardEvent) : void
        {
            this.ctrlDown = false;
            return;
        }// end function

        protected function keyDown(event:KeyboardEvent) : void
        {
            this.ctrlDown = true;
            return;
        }// end function

        private function faceSelect(event:MouseEvent) : void
        {
            event.stopPropagation();
            if (this.ta.text == "请输入聊天内容" || this.ta.text == "请输入聊天内容，按回车键发送")
            {
                this.ta.text = "";
            }
            this.ta.appendText(event.currentTarget.dataSource.protocol);
            this.visible = this.ctrlDown;
            if (!this.ctrlDown)
            {
                if (this.ta is TextArea)
                {
                    GlobalLayer.instance.root.focus = this.ta.textField;
                }
                else if (this.ta is TextInput)
                {
                    GlobalLayer.instance.root.focus = this.ta.textField;
                }
                else
                {
                    GlobalLayer.instance.root.focus = this.ta;
                }
            }
            return;
        }// end function

        protected function doStop(event:MouseEvent) : void
        {
            event.stopPropagation();
            return;
        }// end function

        private function faceRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Clip = null;
            if (param2 < list_face.length)
            {
                _loc_3 = list_face.array[param2];
                _loc_4 = param1.getChildByName("clip") as Clip;
                if (_loc_4)
                {
                    _loc_4.url = "png.common." + _loc_3.icon;
                    _loc_4.clipX = _loc_3.times;
                    _loc_4.interval = 900 / _loc_3.times + 60;
                }
                else
                {
                    _loc_4 = new Clip("png.common." + _loc_3.icon, _loc_3.times, 1);
                    _loc_4.autoPlay = true;
                    _loc_4.name = "clip";
                    _loc_4.interval = 900 / _loc_3.times + 60;
                    param1.addChild(_loc_4);
                }
                param1.removeEventListener(MouseEvent.CLICK, this.faceSelect);
                param1.addEventListener(MouseEvent.CLICK, this.faceSelect);
            }
            return;
        }// end function

    }
}
